package licode.unisop.client.vo;

import lombok.Getter;
import org.springframework.util.Assert;

/**
 * 角色、权限校验的返回码
 */
@Getter
public class SopVerifyCode {

    public static final SopVerifyCode OK = new SopVerifyCode(0);
    public static final SopVerifyCode NO_LOGIN = new SopVerifyCode(1);
    public static final SopVerifyCode FAIL = new SopVerifyCode(-1);
    public static final SopVerifyCode NO_CODE = new SopVerifyCode(-2);

    private final Integer state;

    private SopVerifyCode(Integer state) {
        this.state = state;
    }

    public static SopVerifyCode build(Integer state) {
        if (SopVerifyCode.OK.getState().equals(state)) {
            return SopVerifyCode.OK;
        } else if (SopVerifyCode.NO_LOGIN.getState().equals(state)) {
            return SopVerifyCode.NO_LOGIN;
        } else if (SopVerifyCode.FAIL.getState().equals(state)) {
            return SopVerifyCode.FAIL;
        } else if (SopVerifyCode.NO_CODE.getState().equals(state)) {
            return SopVerifyCode.NO_CODE;
        } else {
            Assert.isTrue(false,
                    "非法的角色权限状态：" + state);
        }
        return null;
    }

    public boolean isOk() {
        return SopVerifyCode.OK.getState().equals(state);
    }

    public boolean isFail() {
        return SopVerifyCode.FAIL.getState().equals(state);
    }

    public boolean isNoLogin() {
        return SopVerifyCode.NO_LOGIN.getState().equals(state);
    }

}
